package com.yunding.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import com.yunding.entity.FreeClass;
import com.yunding.entity.Students;
import com.yunding.exception.ServiceException;
import com.yunding.mapper.StudentMapper;
import com.yunding.service.StudentService;
import com.yunding.vo.StudentSimpleVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;

/**
 * @author guorui
 * @date 2020-10-02 14:52
 */
@Service
@Slf4j
public class StudentsServiceImpl extends ServiceImpl<StudentMapper, Students> implements StudentService {
    @Resource
    private StudentMapper studentMapper;


    /**
     * 根据学生ID和学生姓名查询学生详细信息
     *
     * @param studentId 学号
     * @param studentName 学生姓名
     */
    @Override
    public StudentSimpleVo selectStudents(String studentId, String studentName) {
        Students students = studentMapper.selectById(studentId);
        if(students == null){
            throw new ServiceException("该学号不存在");
        }else if(!students.getStudentName().equals(studentName)){
            throw new ServiceException("学号和姓名不对应");
        }
        StudentSimpleVo studentSimpleVo = new StudentSimpleVo();
        BeanUtils.copyProperties(students,studentSimpleVo);

        return studentSimpleVo;
    }
}
